<?php
/* Description: This file is used to add sub sub category. */
#########IncludeFiles####################################################################################
include_once '../inc/config.php';
include_once("../inc/bootstrape.php");
require_once _SITE_PATH_.'classes/Vendor/Vendor.php';
require_once _SITE_PATH_.'classes/Category/Category.php';
require_once _SITE_PATH_.'classes/CommonUtility/CommonUtility.php';

$category_id = isset($_REQUEST['category_id'])?$_REQUEST['category_id']:'';
$cancleURL = _SITE_ADMIN_URL_.'category/subsubcategory_mng.php?category_id='.$category_id ;

if( $_POST['submit']=='Submit'){    
    $parms['name'] = $_POST['name'];
	$parms['parent_id'] = $_POST['parent_id'];
	$parms['depth'] = 2;
	$parms['added'] = date("Y-m-d h:i:s");
	$parms['modified'] = date("Y-m-d h:i:s");;
        
    if( $cat_id = CommonUtility::insertData($parms, 'category',1)) {        
        $parms = '';
        $parms['category_id'] = $cat_id;
        $parms['added'] = date("Y-m-d h:i:s");
        foreach( $_POST['attributes'] as $i => $val ){
            $parms['attribute_id'] = $val;            
            $parms['unit_id'] = $_POST['unit'][$i];
            $parms['required'] = '0';
            if( $_POST['comp_'.$i] == 1){
                $parms['required'] = '1';
            }
            CommonUtility::insertData($parms, 'category_attributes');
        }
            
        header("Location: subsubcategory_mng.php?category_id=".$category_id."&msg=1098");            
        exit;
    }
    $err = 1099;    
}

$parent_id = Category::getParentId($category_id);

$main_categories = array();
$main_categories = Category::getMainCategories();

$sub_categories = array();
$sub_categories = Category::getSubCategories($parent_id);

$errMsg = $err;
$_tplName = 'category/subsubcategory_add.tpl';
$_title = 'Add Sub-Sub-Category';

$condition['status']='1';
$attribute = CommonUtility::getData($parms=null, $table='attribute_master', $condition);
foreach($attribute as $row){
    $attributeStr .= '<option value="'.$row['id'].'">'.$row['title'].'</option>';
}

$unitRec = CommonUtility::getData($parms=null, $table='unit_master', $condition);
foreach($unitRec as $row){
    $unitStr .= '<option value="'.$row['id'].'">'.$row['title'].'</option>';
}

require_once _ADMIN_TPL_MAIN_;
?>